import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './unpaid.scss'

export default class Index extends Component {
  constructor(props) {
  	super(props);
    this.state = {
      goodslist:[],
      pageheight:0,
	  	pageNumber:0,//页码数
      scrollPd:false,//是否可滑动
      hasNextPage:false,//是否有下一页
    }
  }
  config = {
    navigationBarTitleText: '提现记录'
  }

  componentWillMount () {
		this.getunpaid(0)
  }
  componentDidMount () {}
  componentDidShow () {}
  getunpaid(pageNumber){
    var _this=this;
    
    var url='/pay/papi/v1.9/withdrawal-record?page='+pageNumber+'&sort=createAt,DESC';
    CommonJs.ajaxRequest(url,'','GET',function(res){
		if(res.data.page<res.data.totalPages){
			var hasNextPage = true
		 }
		 else{
			var hasNextPage = false
		 }
		  
		  if(pageNumber==0){
  				  var results = []
  			}
  			else{
  				  var results = _this.state.goodslist
  			}
		  var result = res.data.list;
		  for(var i = 0; i < result.length; i++){
				results.push(result[i])
		  }
		  if (hasNextPage) {
			_this.setState({
			  goodslist:results,
			  pageNumber: res.data.page,
			  hasNextPage: hasNextPage,
			  scrollPd: true
			})
		  }
		  else {
			_this.setState({
			  goodslist:results,
			  pageNumber: res.data.page,
			  hasNextPage: hasNextPage,
			  scrollPd: false
			})
		  }

    },'wfw')
  }

  open(url){

    CommonJs.open(url);
  }
  
  loadMore(){
    var _this = this;
    var pd = _this.state.scrollPd;
    if(pd) {
      //防止多次触发滑动到底部事件
      _this.setState({
        scrollPd: false//禁止下拉
      })
      var pageNumber = _this.state.pageNumber + 1;
      _this.getunpaid(pageNumber)
    }else{
      var hasNextPage =  _this.state.hasNextPage;
      if(hasNextPage){
        Taro.showToast({
            title:'正在加载数据...',
            icon: 'none',
            duration: 2000
          });
      }else{
        Taro.showToast({
            title:'没有更多数据啦！',
            icon: 'none',
            duration: 2000
          });
      }
    }
  }
  
  cancel(id){
	var url='/pay/papi/v1.9/withdrawal-record/cancelWithdrwal/'+id
	var _this=this;
	Taro.showModal({
	  title: '操作提示',
	  content: '是否确定',
	  success(ret){
		  if(ret.confirm){
			CommonJs.ajaxRequest(url,'','PUT',function(res){
			  Taro.showToast({
				title:'操作成功，数据刷新中',
				icon: 'none',
				duration: 2000
			  });
			  setTimeout(function(){
					_this.getunpaid(0)
			  },2000)
			},'wfw')
		  }
		}
	})
  }
  
  render () {
    const result = this.state.goodslist
    return (
      <View className='page'>
        <ScrollView className='qun-goods' scrollY='true' style='height:100%' onScrollToLower={this.loadMore.bind(this,'')}>
        <View className='qun-znwn' style={result.length!=0?'display:none':'display:block'}>暂无申请记录</View>
        {result.map((item, index) => (
        <View className='goodsorder-content'>
          <View className='goodsorder-unpaid'>
            <View className='unpaid-title'>
              <View className='qun-scallty'>
								<View className='unpaid-state'>{CommonJs.FormatDate(item.createAt)}</View>
								<View className='unpaid-shopname'><Text className='unpaid-tel'>{item.type=='PROFITSHARING'?'提现到微信':'提现到银行卡'}</Text></View>
              </View>
            </View>
            <View className='unpaid-content'>
            
              <View className='unpaid-goods' style="border:none;">
								<View className='unpaid-right'>
                  <View className='unpaid-goodsname'>申请类型：{item.assetsType=='BALANCE_RMB'?'余额提现':item.assetsType=='BALANCE_GXJ'?'共享金提现':'WUC提现'}</View>
                  <View className='unpaid-specifications'>提现数量：{item.assetsAmount/100}</View>
                  <View className='unpaid-total'>
                    <View className='unpaid-num'>实际金额：{item.amount/100}元</View>
                    <View className='unpaid-price'>{item.authStatus=='NOTYET'?'待审核':item.authStatus=='FAIL'?'拒绝':item.authStatus=='PASS'?'已通过':'用户取消'}</View>
                    
                  </View>
                </View>
              </View>
			 
             

            </View>
            <View className='unpaid-mes' style={item.WithdrawalSetting?'':'display:none'}>
              <View className='unpaid-people'>
              	提现手续费：{item.WithdrawalSetting.brokerage}‰,
              	提现比例：{item.assetsType=='BALANCE_GXJ'?item.WithdrawalSetting.balanceGxjRatio+'%':item.assetsType=='BALANCE_RMB'?item.WithdrawalSetting.balanceCreditRmbRatio+'%':item.WithdrawalSetting.balanceRmbRatio+'%'}
              </View>
            </View>
            <View className='unpaid-mes' style={item.type=='PROFITSHARING'?'display:none':''}>
              <View className='unpaid-people'>{item.bank.bankType.name}({item.bank.account})</View>
            </View>
            <View className='unpaid-mes' style={item.authStatus=='FAIL'?'':'display:none'}>
              <View className='unpaid-people'>拒绝原因：{item.reson}</View>
            </View>

            <View className='unpaid-order'>
              <Text className='unpaid-cancel' onClick={this.cancel.bind(this,item.id)} style={item.authStatus=='NOTYET'?'display:':'display:none'}>取消</Text>
			  			
            </View>
          </View>
        </View>
        ))}
        </ScrollView>
      </View>
    )
  }
}
